package com.tianzehua.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author tianzehua
 * @date 2019/03/26
 */
public class NioTest3 {

    public static void main(String[] args) throws  Exception {
        FileOutputStream fileOutputStream = new FileOutputStream("NioTest3.txt");

        FileChannel channel = fileOutputStream.getChannel();

        ByteBuffer byteBuffer = ByteBuffer.allocate(512);

        byte[] bytes = "hello beijing !".getBytes();

        for (int i= 0; i < bytes.length; i++){
            byteBuffer.put(bytes[i]);
        }

        byteBuffer.flip();

        channel.write(byteBuffer);

        fileOutputStream.close();

    }
}
